package com.tengju.payment.application.channel;

import com.tengju.payment.domain.model.BusinessType;
import com.tengju.payment.domain.model.ChannelType;
import com.tengju.payment.domain.model.channel.Channel;
import com.tengju.payment.domain.model.channel.ChannelRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 渠道服务  聚合查询  管理  路由等能力
 */
@Service
@Slf4j
public class ChannelRouteService {

    @Resource
    private ChannelRepository channelRepository;

    @Value("${payment.transfer.channel}")
    private String transferChannel;

    public Channel channelRouting(BusinessType businessType, Integer certificationType) {
//        List<Map<String, String>> transferChannelList = JsonUtil.toList(transferChannel, new TypeReference<List<Map<String, String>>>() {
//        });
//        ChannelType channelType = ChannelType.CITIC_BANK;
//        if (CollectionUtils.isEmpty(transferChannelList)) {
//            throw ApplicationException.error(TRANSFER_CHANNEL_NOT_FOUND);
//        }
//        for (Map<String, String> map : transferChannelList) {
//            String certificationTypeVal = map.get("certificationTypeVal");
//            if (String.valueOf(certificationType).equals(certificationTypeVal)) {
//                String channelTypeVal = map.get("channelTypeVal");
//                if (StringUtils.isEmpty(channelTypeVal)) {
//                    throw ApplicationException.error(TRANSFER_CHANNEL_NOT_FOUND);
//                } else {
//                    channelType = ChannelType.fromVal(Integer.parseInt(channelTypeVal));
//                }
//            }
//        }
        return channelRepository.findByBusinessChannelType(businessType, ChannelType.PING_AN_DEPOSITORY);
    }
}
